package com.xcesys.extras.remoting.schedule;

import java.util.Collection;
import java.util.Date;
import java.util.List;

import javax.jws.WebService;

import com.xcesys.extras.dataobject.schedule.JobDataObject;
import com.xcesys.extras.dataobject.schedule.JobLog;
import com.xcesys.extras.dataobject.schedule.TriggerDataObject;

/**
 * Schedule管理服务类
 * 
 * @author LiangShenFan
 */
@WebService(targetNamespace = "com.xcesys.extras.remoting.schedule", serviceName = "ScheduleManagerService")
public interface RScheduleManagerService {

	public void addOrUpdateJob(JobDataObject jobDataObject);

	/**
	 * Updates job and trigger. if job and trigger do not exist, new object
	 * created.
	 * 
	 * @param object
	 */
	public TriggerDataObject addOrUpdateTrigger(TriggerDataObject object);

	/**
	 * @return
	 */
	public String checkStatus();

	/**
	 * <p>
	 * Delete the identified <code>Job</code> from the Scheduler - and any
	 * associated <code>Trigger</code>s.
	 * </p>
	 */
	public void deleteJob(String jobName, String groupName);

	public void deleteTrigger(String triggerName, String triggerGroup,
			String jobName);

	/**
	 * Returns all job group names.
	 * 
	 * @return job group names
	 */
	public List<String> getAllJobGroups();

	/**
	 * Returns an array of predefined JobDetail bean names from quartz factory.
	 * 
	 * @param jobGroup
	 *            Job group name.
	 * 
	 * @return an array of JobDetail bean names.
	 */
	public List<String> getAllJobNamesFromQuartz(String jobGroup);

	/**
	 * Returns an array of predefined JobDetail bean names from spring
	 * container.
	 * 
	 * @param jobGroup
	 *            Job group name.
	 * 
	 * @return an array of JobDetail bean names.
	 */
	public List<String> getAllJobNamesFromSpring(String jobGroup);

	/**
	 * Returns a collection of {@link JobDataObject} from scheduler job detail.
	 * 
	 * @param jobGroups
	 *            Job group names.
	 * @return Returns a collection of {@link JobDataObject}
	 */
	public List<JobDataObject> getAllJobs(List<String> jobGroups);

	/**
	 * Returns all triggers with specified trigger group names.
	 * 
	 * @param trigerGroupNames
	 *            trigger group names.
	 * 
	 * @return TriggerDataObject List.
	 */
	public Collection<TriggerDataObject> getAllTrigers(
			List<String> trigerGroupNames);

	/**
	 * Returns all trigger group names.
	 * 
	 * @return trigger group names
	 */
	public List<String> getAllTriggerGroups();

	/**
	 * Returns a JobDetail bean predefined from quartz factory.
	 * 
	 * @param jobName
	 *            Job name.
	 * @return JobDataObject information.
	 */
	public JobDataObject getJobFromQuartz(String jobName);

	/**
	 * Returns a JobDetail bean predefined from spring IoC container.
	 * 
	 * @param beanName
	 *            JobDetail bean name.
	 * @return JobDetail information.
	 */
	public JobDataObject getJobFromSpring(String beanName);

	/**
	 * Returns a collection of JobLog with given unique job name and date.
	 * 
	 * @param triggerName
	 *            Trigger name.
	 * @param jobName
	 *            job name.
	 * @param lastDate
	 * 
	 * @return a collection of JobLog
	 */
	public Collection<JobLog> getJobLogs(String triggerName, String jobName,
			Date lastDate);

	/**
	 * Pause all triggers.
	 */
	public void pauseAllTriggers();

	/**
	 * <p>
	 * Pause the <code>{@link Trigger}</code> with the given name.
	 * </p>
	 * 
	 * @param triggers
	 *            An array of triggers'.
	 * 
	 * @see #resumeTrigger(String, String)
	 */
	public void pauseTrigger(List<TriggerDataObject> triggers);

	/**
	 * <p>
	 * Remove (delete) the <code>{@link org.quartz.Trigger}</code> with the
	 * given name, and store the new given one - which must be associated with
	 * the same job (the new trigger must have the job name & group specified) -
	 * however, the new trigger need not have the same name as the old trigger.
	 * </p>
	 * 
	 * @param triggers
	 *            The new <code>Trigger</code> to be stored.
	 */
	public void rescheduleJob(List<TriggerDataObject> triggers);

	/**
	 * Resume all triggers from paused state.
	 */
	public void resumeAllTriggers();

	/**
	 * Resume a trigger with specified trigger name and trigger group name.
	 * 
	 * @param triggerName
	 *            trigger name.
	 * @param groupName
	 *            trigger group name.
	 */
	public void resumeTrigger(String triggerName, String groupName);

	/**
	 * <p>
	 * Schedule the given <code>{@link org.quartz.Trigger}</code> with the
	 * <code>Job</code> identified by the <code>Trigger</code>'s settings.
	 * </p>
	 */
	public Date scheduleJobByTriger(TriggerDataObject trigger);

	/**
	 * <p>
	 * Halts the <code>Scheduler</code>'s firing of
	 * <code>{@link Trigger}s</code>, and cleans up all resources associated
	 * with the Scheduler. Equivalent to <code>shutdown(false)</code>.
	 * </p>
	 * 
	 * <p>
	 * The scheduler cannot be re-started.
	 * </p>
	 * 
	 * @see #shutdown(boolean)
	 */
	public void shutdown();

	/**
	 * <p>
	 * Starts the <code>Scheduler</code>'s threads that fire
	 * <code>{@link Trigger}s</code>. When a scheduler is first created it is in
	 * "stand-by" mode, and will not fire triggers. The scheduler can also be
	 * put into stand-by mode by calling the <code>standby()</code> method.
	 * </p>
	 * 
	 * <p>
	 * The misfire/recovery process will be started, if it is the initial call
	 * to this method on this scheduler instance.
	 * </p>
	 * 
	 * @see #standby
	 * @see #shutdown
	 */
	public void start();

	/**
	 * 
	 * Triggers a job (do it now).
	 * 
	 * @param jobName
	 *            job name.
	 * @param groupName
	 *            job group name.
	 */
	public void triggerJob(String jobName, String groupName);
}
